// Copyright 2012. InMobi. All Rights reserved

package com.inmobi.sharedlock;

/**
 * Simple implementation. No thread safety guarantee of any kind.
 */
public class SimpleCalculator implements AverageCalculator {

  private volatile long sum = 0;

  private volatile int count = 0;
  
  @Override
  public void addValue(long value) {
    count++;
    sum += value;
  }

  @Override
  public double getAverage() {
    return count != 0 ? sum * 1.0 / count : 0.0;
  }
}
